<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/mui.indexedlist.css" rel="stylesheet" />
		<style>
			html,
			body {
				height: 100%;
				overflow: hidden;
			}
			
			.mui-bar {
				-webkit-box-shadow: none;
				box-shadow: none;
			}
			
			.oa-contact-cell.mui-table .mui-table-cell {
				padding: 10px 0;
				vertical-align: middle;
			}
			
			.oa-contact-cell {
				position: relative;
				margin: -11px 0;
			}
			
			.oa-contact-avatar {
				width: 75px;
			}
			
			.oa-contact-avatar img {
				border-radius: 50%;
				width: 50px;
				height: 50px;
			}
			
			.oa-contact-content {
				width: 100%;
			}
			
			.oa-contact-name {
				margin-right: 20px;
			}
			
			.oa-contact-name,
			.oa-contact-position {
				float: left;
			}
		</style>
	</head>

	<body>

		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" style="font-weight: bold;">通讯录</h1>
		</header>

		<div class="mui-content">
			<div id='list' class="mui-indexed-list">
				<div class="mui-indexed-list-search mui-input-row mui-search">
					<input type="search" class="mui-input-clear mui-indexed-list-search-input" placeholder="搜索用户">
				</div>
				<div class="mui-indexed-list-bar">
					<a>A</a>
					<a>B</a>
					<a>C</a>
					<a>D</a>
					<a>E</a>
					<a>F</a>
					<a>G</a>
					<a>H</a>
					<a>I</a>
					<a>J</a>
					<a>K</a>
					<a>L</a>
					<a>M</a>
					<a>N</a>
					<a>O</a>
					<a>P</a>
					<a>Q</a>
					<a>R</a>
					<a>S</a>
					<a>T</a>
					<a>U</a>
					<a>V</a>
					<a>W</a>
					<a>X</a>
					<a>Y</a>
					<a>Z</a>
				</div>
				<div class="mui-indexed-list-alert"></div>
				<div class="mui-indexed-list-inner">
					<div class="mui-indexed-list-empty-alert">没有数据</div>
					<ul class="mui-table-view mui-table-view-striped mui-table-view-condensed" id="maillist">
						<!--
                        	
						<li data-value="AOTEMAN" data-tags="AoTeMan" class="mui-table-view-cell mui-indexed-list-item">
							<div class="mui-slider-cell">
								<div class="oa-contact-cell mui-table">
									<div class="oa-contact-avatar mui-table-cell">
										<img src="images/user-photo.png" onclick="update();" />
									</div>
									<div class="oa-contact-content mui-table-cell">
										<div class="mui-clearfix">
											<h4 class="oa-contact-name">奥特曼</h4>
											<span class="oa-contact-position mui-h6">开发商</span>
										</div>
										<p class="oa-contact-address mui-h6">
											师院9栋426
										</p>
									</div>
								</div>
							</div>
						</li>

						<li data-value="ZHA" data-tags="WangCai" class="mui-table-view-cell mui-indexed-list-item">
							<div class="mui-slider-cell">
								<div class="oa-contact-cell mui-table">
									<div class="oa-contact-avatar mui-table-cell">
										<img src="images/user-photo.png" onclick="update();" />
									</div>
									<div class="oa-contact-content mui-table-cell">
										<div class="mui-clearfix">
											<h4 class="oa-contact-name">旺财</h4>
											<span class="oa-contact-position mui-h6">管理人员</span>
										</div>
										<p class="oa-contact-address mui-h6">
											科院7栋225
										</p>
									</div>
								</div>
							</div>
						</li>

						<li data-value="XM" data-tags="XiaoMing" class="mui-table-view-cell mui-indexed-list-item">
							<div class="mui-slider-cell">
								<div class="oa-contact-cell mui-table">
									<div class="oa-contact-avatar mui-table-cell">
										<img src="images/user-photo.png" onclick="update();" />
									</div>
									<div class="oa-contact-content mui-table-cell">
										<div class="mui-clearfix">
											<h4 class="oa-contact-name">小明</h4>
											<span class="oa-contact-position mui-h6">用户</span>
										</div>
										<p class="oa-contact-address mui-h6">
											浍河欣城40栋2401
										</p>
									</div>
								</div>
							</div>
						</li>

						<li data-value="ZHA" data-tags="XiaoMing" class="mui-table-view-cell mui-indexed-list-item">
							<div class="mui-slider-cell">
								<div class="oa-contact-cell mui-table">
									<div class="oa-contact-avatar mui-table-cell">
										<img src="images/user-photo.png" onclick="update();" />
									</div>
									<div class="oa-contact-content mui-table-cell">
										<div class="mui-clearfix">
											<h4 class="oa-contact-name">张去</h4>
											<span class="oa-contact-position mui-h6">用户</span>
										</div>
										<p class="oa-contact-address mui-h6">
											浍河欣城40栋2401
										</p>
									</div>
								</div>
							</div>
						</li>

						<li data-value="LIULIU" data-tags="XiaoMing" class="mui-table-view-cell mui-indexed-list-item">
							<div class="mui-slider-cell">
								<div class="oa-contact-cell mui-table">
									<div class="oa-contact-avatar mui-table-cell">
										<img src="images/user-photo.png" onclick="update();" />
									</div>
									<div class="oa-contact-content mui-table-cell">
										<div class="mui-clearfix">
											<h4 class="oa-contact-name">刘浏</h4>
											<span class="oa-contact-position mui-h6">用户</span>
										</div>
										<p class="oa-contact-address mui-h6">
											浍河欣城40栋2401
										</p>
									</div>
								</div>
							</div>
						</li>
						<li data-value="QQ" data-tags="XiaoMing" class="mui-table-view-cell mui-indexed-list-item">
							<div class="mui-slider-cell">
								<div class="oa-contact-cell mui-table">
									<div class="oa-contact-avatar mui-table-cell">
										<img src="images/user-photo.png" onclick="update();" />
									</div>
									<div class="oa-contact-content mui-table-cell">
										<div class="mui-clearfix">
											<h4 class="oa-contact-name">强强</h4>
											<span class="oa-contact-position mui-h6">用户</span>
										</div>
										<p class="oa-contact-address mui-h6">
											浍河欣城40栋2401
										</p>
									</div>
								</div>
							</div>
						</li>
						
						<li data-value="QQ" data-tags="XiaoMing" class="mui-table-view-cell mui-indexed-list-item">
							<div class="mui-slider-cell">
								<div class="oa-contact-cell mui-table">
									<div class="oa-contact-avatar mui-table-cell">
										<img src="images/user-photo.png" onclick="update();" />
									</div>
									<div class="oa-contact-content mui-table-cell" >
										<div class="mui-clearfix" style="overflow: hidden;text-overflow:ellipsis;white-space: nowrap;">
											<h4 class="oa-contact-name">轻轻浍河欣城40栋2401</h4>
											<span class="oa-contact-position mui-h6">用户浍河欣城40栋2401</span>
										</div>
										<p class="oa-contact-address mui-h6" style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">
											浍河欣城40栋2401浍河欣城40栋2401浍河欣城40栋2401浍河欣城40栋2401
										</p>
									</div>
									<div class=" mui-table-cell" style="width: 28%;">
										<input type="button" value="添加好友" style="background-color: green; padding: 5px; color: white; font-weight: bold;font-size: 15px;" />
									</div>
								</div>
							</div>
						</li>
						
						<li data-value="LIQ" data-tags="XiaoMing" class="mui-table-view-cell mui-indexed-list-item">
							<div class="mui-slider-cell">
								<div class="oa-contact-cell mui-table">
									<div class="oa-contact-avatar mui-table-cell">
										<img src="images/user-photo.png" onclick="update();" />
									</div>
									<div class="oa-contact-content mui-table-cell">
										<div class="mui-clearfix" style="-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">
											<div class="oa-contact-name">李青4007883333,18290209497申请加您为好友</div>
										</div>
										<p class="oa-contact-address mui-h6" style="margin-top: 2px;" style="overflow: hidden;text-overflow:ellipsis;white-space: nowrap;">
											手机：18888888888
										</p>
									</div>
									<div class=" mui-table-cell" style="width: 90px;text-align: center;right: -15px;">
										<input type="button" onclick="friendno('{{uinfo}}')" value="拒绝" style="float:right;background-color: #CE272D; padding: 4px; color: white; font-weight: bold;font-size: 15px;" />
										<input type="button" onclick="friendok('{{uinfo}}')" value="添加" style="float:right; background-color: dodgerblue; padding: 4px; color: white; font-weight: bold;font-size: 15px;" />
									</div>
								</div>
							</div>
							
						</li>
						         作者：1471846120@qq.com
                        	时间：2018-03-20
                        	描述： 
                        -->
					</ul>
				</div>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/mui.indexedlist.js"></script>
		<script src="js/jquery-1.8.3.js"></script>
		<script src="js/ServerURL.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" charset="utf-8">
			mui.init();
			mui.ready(function() {
				var header = document.querySelector('header.mui-bar');
				var list = document.getElementById('list');
				//calc hieght
				list.style.height = (document.body.offsetHeight - header.offsetHeight) + 'px';
				//create
				window.indexedList = new mui.IndexedList(list);
			});
			//          function update(){
			//              open("personInformation_show.html");
			//          }
		</script>
		<!--app通讯录好友模板-->
		<script type="text/html" id="list-tongxunlu">
			<li data-value="{{titleName}}" data-tags="{{titleName}}" class="mui-table-view-cell mui-indexed-list-item" onclick="liaotian('{{fid}}','{{titleName}}');">
				<div class="mui-slider-cell">
					<div class="oa-contact-cell mui-table">
						<div class="oa-contact-avatar mui-table-cell">
							<img src="{{images}}" onclick="update();" />
						</div>
						<div class="oa-contact-content mui-table-cell">
							<div class="mui-clearfix">
								<h4 class="oa-contact-name">{{tongxunName}}</h4>
								<span class="oa-contact-position mui-h6">{{listtype}}</span>
							</div>
							<p class="oa-contact-address mui-h6">
								{{content}}
							</p>
						</div>
					</div>
				</div>
			</li>
		</script>
		<!--本地通讯录好友模板-->
		<script type="text/html" id="list-tongxunlu1">
			<li data-value="{{titleName}}" data-tags="{{titleName}}" class="mui-table-view-cell mui-indexed-list-item">
				<div class="mui-slider-cell">
					<div class="oa-contact-cell mui-table">
						<div class="oa-contact-avatar mui-table-cell">
							<img src="{{images}}" onclick="update();" />
						</div>
						<div class="oa-contact-content mui-table-cell" style="overflow: hidden;text-overflow:ellipsis;white-space: nowrap;">
							<div class="mui-clearfix">
								<h4 class="oa-contact-name">{{tongxunName}}</h4>
								<span class="oa-contact-position mui-h6">{{listtype}}</span>
							</div>
							<p class="oa-contact-address mui-h6" style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">
								{{content}}
							</p>
						</div>
						<div class=" mui-table-cell" style="width: 28%;text-align: center;">
							<input type="button" onclick="addfriend('{{phoneinfo}}','{{uinfo}}')" value="{{xianshinanme}}" style="background-color: green; padding: 3px; color: white; font-weight: bold;font-size: 15px;" />
						</div>
					</div>
				</div>
			</li>
		</script>
		<!--添加好友模板-->
		<script type="text/html" id="list-tongxunlu2">
			<li data-value="#" data-tags="#" class="mui-table-view-cell mui-indexed-list-item">
				<div class="mui-slider-cell">
					<div class="oa-contact-cell mui-table">
						<div class="oa-contact-avatar mui-table-cell">
							<img src="{{images}}" />
						</div>
						<div class="oa-contact-content mui-table-cell">
							<div class="mui-clearfix" style="-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">
								<div class="oa-contact-name">{{tongxunName}}</div>
							</div>
							<p class="oa-contact-address mui-h6" style="margin-top: 2px;" style="overflow: hidden;text-overflow:ellipsis;white-space: nowrap;">
								手机:{{content}}
							</p>
						</div>
						<div class=" mui-table-cell" style="width: 88px;text-align: center;right: -20px;">
							<input type="button" onclick="friendno('{{uinfo}}','{{ids}}')" value="拒绝" style="float:right;background-color: #CE272D; padding: 4px; color: white; font-weight: bold;font-size: 15px;" />
							<input type="button" onclick="friendok('{{uinfo}}','{{ids}}')" value="添加" style="float:right; background-color: dodgerblue; padding: 4px; color: white; font-weight: bold;font-size: 15px;" />
						</div>
					</div>
				</div>
			</li>
		</script>
		<script type="text/javascript">
			var btnArray = ['确定', '取消'];
			//预启动
			window.onload = function() {
				mui.plusReady(function() {
					//获取本地得通讯录
					// 扩展API加载完毕，现在可以正常调用扩展API
					plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) {
						addressbook.find(["displayName", "phoneNumbers"], function(contacts) {

							//获取添加服务器通讯录
							getservermail();
							//本地通讯录开始核对,核对后添加到显示
							gethedui(contacts);
							//获取申请通讯好友列表
							getshenqing();

						}, function() {
							mui.toast("获取电话簿失败 ");
						}, {
							multiple: true
						});
					}, function(e) {
						mui.toast("获取电话簿失败 " + e.message);
					});
					//自定义一个方法批量替换制定的字符 
					function del_html_tags(str, reallyDo, replaceWith) {
						var e = new RegExp(reallyDo, "g");
						words = str.replace(e, replaceWith);
						return words;
					}
				});
			}

			function getshenqing() {

				var loginID = localStorage.getItem("loginID");
				mui.ajax({
					type: "post",
					url: ServerURL + '/selectFriend',
					async: true,
					data: {
						"status": "2",
						"userId": loginID
						//"userId":"3393e986607546bb8870f1ff42185f70"
					},
					dataType: "jsonp",
					jsonp: "jsoncallback",
					timeout: 1000, //超时时间设置为1秒；
					headers: {
						'Content-Type': 'application/json'
					},
					success: function(data, status, xhr) {
						var successString = JSON.parse(data);
						//console.log("刷新的聊天记录数据内容为 : " + data);
						var codelog = successString.code;
						if(codelog != "-1") {
							console.log("返回的新消息为 : " + successString.data.length + "条");
							var listslength = successString.data.length;
							var contacts = successString.data;
							if(listslength > 0) {
								//获取题干模板 
								for(var i = 0; i < listslength; i++) {
									tiganStr = $("#list-tongxunlu2").html();
									//替换相关的字段值 
									tiganStr = del_html_tags(tiganStr, "{{uinfo}}", contacts[i].friendId); //修改用户ID的值 
									tiganStr = del_html_tags(tiganStr, "{{tongxunName}}", contacts[i].name + "申请加您为好友"); //添加题目内容
									tiganStr = del_html_tags(tiganStr, "{{ids}}", contacts[i].id); 
									tiganStr = del_html_tags(tiganStr, "{{content}}", contacts[i].phone); //修改手机值
									//								var headImg = contacts[i].headImg;
									//								if(null != headImg && undefined != headImg) {
									//									tiganStr = del_html_tags(tiganStr, "{{images}}", contacts[i].headImg);
									//								} else {
									tiganStr = del_html_tags(tiganStr, "{{images}}", "images/user-photo.png");
									//								}
									$("#maillist").prepend(tiganStr); //替换之后追加到选项中去
								}
							}
						} else if(codelog == "-1") {

							//mui.toast('网络连接错误！');
						} else {

							//mui.toast('无聊天记录列表');
						}
						return data;
					},
					error: function(xhr, type, errorThrown) {
						console.log("error: " + type);

						return "获取数据失败：服务器错误！";
					}
				});

			}

			function getservermail() {
				var loginID = localStorage.getItem("loginID");
				mui.ajax({
					type: "post",
					url: ServerURL + '/user/queryUserAddressBook',
					async: false,
					data: {
						//"id" : "2b294a27bc87450f84556c70ffba5c01",
						"id": loginID
					},
					dataType: "jsonp",
					jsonp: "jsoncallback",
					timeout: 500, //超时时间设置为1秒；
					headers: {
						'Content-Type': 'application/json'
					},
					success: function(data, status, xhr) {
						var successString = JSON.parse(data);
						console.log("返回的通讯录数据内容为 : " + data);
						var codelog = successString.code;
						if(codelog == 0) {
							//console.log("返回的数据list内容长度为 : " + successString.data.list.length);
							var listlength = successString.data.length;
							var contacts = successString.data;
							//开始加入缓存
							localStorage.setItem("queryUserAddressBook", data);
							//获取题干模板 
							for(var i = 0; i < contacts.length; i++) {
								tiganStr = $("#list-tongxunlu").html();
								//替换相关的字段值 
								tiganStr = del_html_tags(tiganStr, "{{fid}}", contacts[i].id); //修改用户ID的值 
								tiganStr = del_html_tags(tiganStr, "{{tongxunName}}", contacts[i].name); //添加题目内容
								tiganStr = del_html_tags(tiganStr, "{{titleName}}", contacts[i].name); //修改搜索的值 
								var headImg = contacts[i].headImg;
								if(null != headImg && undefined != headImg) {
									tiganStr = del_html_tags(tiganStr, "{{images}}", contacts[i].headImg);
								} else {
									tiganStr = del_html_tags(tiganStr, "{{images}}", "images/user-photo.png");
								}
								tiganStr = del_html_tags(tiganStr, "{{listtype}}", "APP好友");
								tiganStr = del_html_tags(tiganStr, "{{content}}", "手机号：" + (contacts[i].phone.length == 0 ? "" : contacts[i].phone));
								$("#maillist").append(tiganStr); //替换之后追加到选项中去
							}
						} else if(codelog == "-1") {
							readingcache();
							mui.toast('网络连接错误！');
						} else {
							readingcache();
							mui.toast('无在线通讯录列表');
						}
						return data;
					},
					error: function(xhr, type, errorThrown) {
						console.log("error: " + type);
						readingcache();
						return "获取数据失败：服务器错误！";
					}
				});
			}

			//读取缓存
			function readingcache() {
				//请求数据
				var loginID = localStorage.getItem("loginID");
				var listdatas = localStorage.getItem("queryUserAddressBook");
				var successString = JSON.parse(listdatas);

				//console.log("缓存的通讯录数据内容为 : " + listdatas);
				//console.log("返回的数据list内容长度为 : " + successString.data.list.length);
				var listlength = successString.data.length;
				var contacts = successString.data;
				//获取题干模板 
				for(var i = 0; i < contacts.length; i++) {
					tiganStr = $("#list-tongxunlu").html();
					//替换相关的字段值 
					tiganStr = del_html_tags(tiganStr, "{{fid}}", contacts[i].id); //修改用户ID的值 
					tiganStr = del_html_tags(tiganStr, "{{tongxunName}}", contacts[i].name); //添加题目内容
					tiganStr = del_html_tags(tiganStr, "{{titleName}}", contacts[i].name); //修改搜索的值 
					var headImg = contacts[i].headImg;
					if(null != headImg && undefined != headImg) {
						tiganStr = del_html_tags(tiganStr, "{{images}}", contacts[i].headImg);
					} else {
						tiganStr = del_html_tags(tiganStr, "{{images}}", "images/user-photo.png");
					}
					tiganStr = del_html_tags(tiganStr, "{{listtype}}", "APP好友");
					tiganStr = del_html_tags(tiganStr, "{{content}}", "手机号：" + (contacts[i].phone.length == 0 ? "" : contacts[i].phone));
					$("#maillist").append(tiganStr); //替换之后追加到选项中去
				}

			}

			function gethedui(contacts) {
				var heiduicontacts = contacts;
				var loginID = localStorage.getItem("loginID");
				var Myphone = localStorage.getItem("Myphone");
				//创建电话数组
				var phonelist = new Array();
				var heduijieguo = new Array();
				for(var i = 0, len = heiduicontacts.length; i < len; i++) {
					//去除空格
					var ss = heiduicontacts[i].phoneNumbers[0].value;
					var reg = /\s/g;
					var okstring = ss.replace(reg, "");
					phonelist.push(okstring);
				}
				console.log("phonelist:" + phonelist);

				mui.ajax({
					type: "post",
					url: ServerURL + '/isFriendByPhone',
					async: false,
					data: {
						"friendPhoneList": phonelist,
						"userPhone": Myphone
					},
					dataType: "jsonp",
					jsonp: "jsoncallback",
					timeout: 1000, //超时时间设置为1秒；
					headers: {
						'Content-Type': 'application/json'
					},
					success: function(data, status, xhr) {
						var successString = JSON.parse(data);
						console.log("返回的通讯录核对数据内容为 : " + data);
						var codelog = successString.code;
						if(codelog == 0) {
							//开始加入核对缓存
							localStorage.setItem("isFriendByPhone", data);
							var listlength = successString.data[0].friendInfo.length;
							console.log("返回的核对数据list内容长度为 : " + listlength);
							//heduijieguo = successString.data[0].friendInfo[0];
							//console.log("返回的核对list内容为 : " + heduijieguo);
							//获取题干模板 
							for(var i = 0; i < listlength; i++) {
								heduijieguo.push(successString.data[0].friendInfo[i].isFriend);
							}
							console.log("核对结果列表:" + heduijieguo);
							for(var i = 0, len = contacts.length; i < len; i++) {
								//不是app好友显示并有添加好友得按钮
								if(heduijieguo[i] == "否") {
									tiganStr = $("#list-tongxunlu1").html();
									//替换相关的字段值 
									//tiganStr = del_html_tags(tiganStr, "{{num}}", i); //修改ID的值 
									tiganStr = del_html_tags(tiganStr, "{{tongxunName}}", contacts[i].displayName); //添加题目内容
									tiganStr = del_html_tags(tiganStr, "{{titleName}}", contacts[i].displayName); //修改搜索的值 
									var photos = contacts[i].photos;
									if(null != photos && undefined != photos) {
										tiganStr = del_html_tags(tiganStr, "{{images}}", contacts[i].photos);
									} else {
										tiganStr = del_html_tags(tiganStr, "{{images}}", "images/user-photo.png");
									}
									if(successString.data[0].friendInfo[i].isFriend.indexOf("userId") != -1) {
										tiganStr = del_html_tags(tiganStr, "{{uinfo}}", successString.data[0].friendInfo[i].userId);
										tiganStr = del_html_tags(tiganStr, "{{xianshinanme}}", "添加好友");
									} else {
										tiganStr = del_html_tags(tiganStr, "{{xianshinanme}}", "邀请注册");
									}
									tiganStr = del_html_tags(tiganStr, "{{listtype}}", "通讯录好友");
									tiganStr = del_html_tags(tiganStr, "{{content}}", "手机号：" + (contacts[i].phoneNumbers.length == 0 ? "" : contacts[i].phoneNumbers[0].value));
									tiganStr = del_html_tags(tiganStr, "{{phoneinfo}}", (contacts[i].phoneNumbers.length == 0 ? "" : contacts[i].phoneNumbers[0].value));
									$("#maillist").append(tiganStr); //替换之后追加到选项中去
								} else {}
							}

						} else if(codelog == "-1") {
							readingheiduicache(heduijieguo, contacts);
							mui.toast('网络连接错误！');
						} else {
							readingheiduicache(heduijieguo, contacts);
							mui.toast('核对通讯录列表出错！');
						}
						return data;
					},
					error: function(xhr, type, errorThrown) {
						readingheiduicache(heduijieguo, contacts);
						console.log("error: " + type);
						return "获取数据失败：服务器错误！";
					}
				});

			}

			function readingheiduicache(heduijieguo, contacts) {
				//请求核对缓存数据
				var loginID = localStorage.getItem("loginID");
				var listdatas = localStorage.getItem("isFriendByPhone");
				var successString = JSON.parse(listdatas);
				var listlength = successString.data[0].friendInfo.length;
				console.log("读取缓存得核对数据list内容长度为 : " + listlength);
				//获取题干模板 
				for(var i = 0; i < listlength; i++) {
					heduijieguo.push(successString.data[0].friendInfo[i].isFriend);
				}
				console.log("核对结果列表:" + heduijieguo);
				for(var i = 0, len = contacts.length; i < len; i++) {
					//不是app好友显示并有添加好友得按钮
					if(heduijieguo[i] == "否") {
						tiganStr = $("#list-tongxunlu1").html();
						//替换相关的字段值 
						//tiganStr = del_html_tags(tiganStr, "{{num}}", i); //修改ID的值 
						tiganStr = del_html_tags(tiganStr, "{{tongxunName}}", contacts[i].displayName); //添加题目内容
						tiganStr = del_html_tags(tiganStr, "{{titleName}}", contacts[i].displayName); //修改搜索的值 
						var photos = contacts[i].photos;
						if(null != photos && undefined != photos) {
							tiganStr = del_html_tags(tiganStr, "{{images}}", contacts[i].photos);
						} else {
							tiganStr = del_html_tags(tiganStr, "{{images}}", "images/user-photo.png");
						}
						if(successString.data[0].friendInfo[i].isFriend.indexOf("userId") != -1) {
							tiganStr = del_html_tags(tiganStr, "{{uinfo}}", successString.data[0].friendInfo[i].userId);
							tiganStr = del_html_tags(tiganStr, "{{xianshinanme}}", "添加好友");
						} else {
							tiganStr = del_html_tags(tiganStr, "{{xianshinanme}}", "邀请注册");
						}
						tiganStr = del_html_tags(tiganStr, "{{listtype}}", "通讯录好友");
						tiganStr = del_html_tags(tiganStr, "{{content}}", "手机号：" + (contacts[i].phoneNumbers.length == 0 ? "" : contacts[i].phoneNumbers[0].value));
						tiganStr = del_html_tags(tiganStr, "{{phoneinfo}}", (contacts[i].phoneNumbers.length == 0 ? "" : contacts[i].phoneNumbers[0].value));
						$("#maillist").append(tiganStr); //替换之后追加到选项中去
					} else {}
				}

			}
			//点击进入对话聊天
			function liaotian(fid, title) {
				//mui.toast(fid);
				mui.openWindow({
					//url: "page1_chat.html",
					//id: "page1_chat.html",
					url: "im-chat.html",
					id: "im-chat.html",
					styles: {
						//top:"40px",//新页面顶部位置
					},
					//打开窗口时传参方法
					extras: {
						title: title,
						tid: fid
					},
					show: {
						autoShow: true,
						aniShow: "slide-in-right",
						duration: 100
					},
					waiting: {
						autoShow: true,
						title: "正在加载中...",
						options: {
							//width: 
							//height:
						}
					}
				})
			}
			//点击发送短信
			function addfriend(fphone, uinfo) {
				mui.toast(uinfo);
				if(uinfo != "{{uinfo}}") {
					mui.confirm('添加该用户为好友', '向该好友发送添加APP好友消息！', btnArray, function(e) {
						//更新
						if(e.index == 0) {
							//提交后刷新页面

							var loginID = localStorage.getItem("loginID");
							mui.ajax({
								type: "post",
								url: ServerURL + '/addFriend',
								async: false,
								data: {
									"friendId": uinfo,
									"status": "2",
									"userId": loginID
								},
								dataType: "jsonp",
								jsonp: "jsoncallback",
								timeout: 1000, //超时时间设置为1秒；
								headers: {
									'Content-Type': 'application/json'
								},
								success: function(data, status, xhr) {
									var successString = JSON.parse(data);
									console.log("返回的添加好友内容为 : " + data);
									var codelog = successString.code;
									if(codelog == 0) {
										//开始加入缓存
										//										var cheche="addFriend"+uinfo;
										//										localStorage.setItem(cheche, t);
										window.location.reload();
									} else if(codelog == "-1") {

										mui.toast('网络连接错误！');
									} else {

										mui.toast('发送添加失败');
									}
									return data;
								},
								error: function(xhr, type, errorThrown) {
									console.log("error: " + type);

									return "发送添加消息失败：服务器错误！";
								}
							});

						} else {

						}
					})
				} else { //不是app用户邀请使用app
					window.location.href = "sms:" + fphone + "?";
				}

			}
			//同意好友申请
			function friendok(tid,ids) {
				mui.confirm('添加该用户为好友', '确认添加该用户为好友?', btnArray, function(e) {
					//更新
					if(e.index == 0) {
						//提交后刷新页面
						var loginID = localStorage.getItem("loginID");
						mui.ajax({
							type: "post",
							url: ServerURL + '/updateFriend',
							async: false,
							data: {
								"friendId": tid,
								"id":ids,
								"status": "0",
								"userId": loginID
							},
							dataType: "jsonp",
							jsonp: "jsoncallback",
							timeout: 1000, //超时时间设置为1秒；
							headers: {
								'Content-Type': 'application/json'
							},
							success: function(data, status, xhr) {
								var successString = JSON.parse(data);
								console.log("返回的添加好友内容为 : " + data);
								var codelog = successString.code;
								if(codelog == 0) {
									//开始加入缓存
									window.location.reload();
								} else if(codelog == "-1") {

									mui.toast('网络连接错误！');
								} else {

									mui.toast('添加好友失败！');
								}
								return data;
							},
							error: function(xhr, type, errorThrown) {
								console.log("error: " + type);

								return "添加好友失败：服务器错误！";
							}
						});

					} else {}
				})
			}
			//拒绝好友申请
			function friendno(tid,ids) {
				mui.confirm('拒绝该用户申请为好友', '确认拒绝该用户申请?', btnArray, function(e) {
					//更新
					if(e.index == 0) {
						//提交后刷新页面
						var loginID = localStorage.getItem("loginID");
						mui.ajax({
							type: "post",
							url: ServerURL + '/updateFriend',
							async: false,
							data: {
								"friendId": tid,
								"status": "3",
								"id":ids,
								"userId": loginID
							},
							dataType: "jsonp",
							jsonp: "jsoncallback",
							timeout: 1000, //超时时间设置为1秒；
							headers: {
								'Content-Type': 'application/json'
							},
							success: function(data, status, xhr) {
								var successString = JSON.parse(data);
								console.log("拒绝该用户好友内容为 : " + data);
								var codelog = successString.code;
								if(codelog == 0) {
									//开始加入缓存
									window.location.reload();
								} else if(codelog == "-1") {
									readingcache();
									mui.toast('网络连接错误！');
								} else {
									readingcache();
									mui.toast('操作失败！');
								}
								return data;
							},
							error: function(xhr, type, errorThrown) {
								console.log("error: " + type);
								readingcache();
								return "操作失败：服务器错误！";
							}
						});
					} else {}
				})
			}

			//自定义一个方法批量替换制定的字符 
			function del_html_tags(str, reallyDo, replaceWith) {
				var e = new RegExp(reallyDo, "g");
				words = str.replace(e, replaceWith);
				return words;
			}
		</script>
	</body>

</html>